//
//  TYZBaseInfo.m
//  TYZ_SC
//
//  Created by 李贤立 on 2017/12/12.
//  Copyright © 2017年 Capfer. All rights reserved.
//

#import "TYZBaseInfo.h"

@interface TYZBaseInfo ()

@end

@implementation TYZBaseInfo
TYZSingleto_m(BaseInfo)
- (NSString *)sendBox {
    if (_sendBox == nil) {
        _sendBox = NSHomeDirectory();
    }
    return _sendBox;
}
- (NSString *)documentPath {
    if (_documentPath == nil) {
        _documentPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES) objectAtIndex:0];
    }
    return _documentPath;
}
- (NSString *)imagesFolder {
    if (_imagesFolder == nil) {
        _imagesFolder = [self.documentPath stringByAppendingPathComponent:@"Images"];
        [[NSFileManager defaultManager] createDirectoryAtPath:_imagesFolder withIntermediateDirectories:NO attributes:nil error:nil];
    }
    return _imagesFolder;
}
- (NSString *)referenceFolder {
    if (_referenceFolder == nil) {
        _referenceFolder = [self.documentPath stringByAppendingPathComponent:@"Reference"];
        [[NSFileManager defaultManager] createDirectoryAtPath:_referenceFolder withIntermediateDirectories:NO attributes:nil error:nil];
    }
    return _referenceFolder;
}
- (NSString *)exitFilePath {
    if (_exitFilePath == nil) {
        _exitFilePath = [self.documentPath stringByAppendingPathComponent:Symbol_ExistFileFolder];
        [[NSFileManager defaultManager] createDirectoryAtPath:_exitFilePath withIntermediateDirectories:NO attributes:nil error:nil];
    }
    return _exitFilePath;
}
- (NSString *)worksFilePath {
    if (_worksFilePath == nil) {
        _worksFilePath = [self.exitFilePath stringByAppendingPathComponent:Symbol_WorksFileFolder];
        [[NSFileManager defaultManager] createDirectoryAtPath:_worksFilePath withIntermediateDirectories:NO attributes:nil error:nil];
    }
    return _worksFilePath;
}
- (NSString *)collectPath {
    if (_collectPath == nil) {
        _collectPath = [self.exitFilePath stringByAppendingPathComponent:Symbol_CollectPlistFile];
    }
    return _collectPath;
}
- (NSString *)duration {
    if (_duration == nil) {
        _duration = [self.documentPath stringByAppendingPathComponent:Symbol_DurationFile];
    }
    return _duration;
}
- (NSArray *)imageArray {
    if (_imageArray == nil) {
        NSMutableArray *imageArray = [NSMutableArray arrayWithCapacity:24];
        NSString *prefix = @"loading_";
        for (int i = 0; i < 24; i ++) {
            UIImage *imgtemp = [UIImage imageNamed:[NSString stringWithFormat:@"%@%d.png", prefix, i]];
            [imageArray addObject:imgtemp];
        }
        _imageArray = [imageArray mutableCopy];
    }
    return _imageArray;
}
- (NSTimer *)countdownTimer {
    if (_countdownTimer == nil) {
        _countdownTimer = [NSTimer timerWithTimeInterval:1.0 target:self selector:@selector(timerAction) userInfo:nil repeats:YES];
    }
    return _countdownTimer;
}
- (void)timerAction {
    self.verifyCountdown ++;
}
- (void)setVerifyCountdown:(NSInteger)verifyCountdown {
    if (verifyCountdown >= Value_VerifyCountdown) {
        verifyCountdown = 0;
        [self.countdownTimer invalidate];
        self.countdownTimer = nil;
    }
    _verifyCountdown = verifyCountdown;
}
- (NSString *)sqlite {
    if (_sqlite == nil) {
        _sqlite = [self.documentPath stringByAppendingPathComponent:@"SCRM.db"];
    }
    return _sqlite;
}
- (NSArray<NSString *> *)settingTypeArray {
    if (_settingTypeArray == nil) {
        _settingTypeArray = @[APP_SETTING_WIFI,
                              APP_SETTING_Bluetooth,
                              APP_SETTING_MOBILE_DATA_SETTINGS_ID,
                              APP_SETTING_INTERNET_TETHERING,
                              APP_SETTING_Carrier,
                              APP_SETTING_NOTIFICATIONS_ID,
                              APP_SETTING_INTERNET_General,
                              APP_SETTING_About,
                              APP_SETTING_Keyboard,
                              APP_SETTING_ACCESSIBILITY,
                              APP_SETTING_INTERNET_INTERNATIONAL,
                              APP_SETTING_Wallpaper,
                              APP_SETTING_SIRI,
                              APP_SETTING_Privacy,
                              APP_SETTING_SAFARI,
                              APP_SETTING_MUSIC,
                              APP_SETTING_MUSICEQ,
                              APP_SETTING_Photos,
                              APP_SETTING_INTERNET_FACETIME];
    }
    return _settingTypeArray;
}
- (void)setConnectType:(ESTConnectType)connectType {
    _connectType = connectType;
    switch (connectType) {
        case CONNECT_EASTON:
            BaseInfo.serverAddress = Network_Address;
            break;
        case CONNECT_HAN:
            BaseInfo.serverAddress = Network_Address_Han;
            break;
        case CONNECT_WU:
            BaseInfo.serverAddress = Network_Address_Wu;
            break;
        default:
            break;
    }
}
- (void)setServerAddress:(NSString *)serverAddress {
    _serverAddress = serverAddress;
    NetTool.url = [NSString stringWithFormat:@"%@%@%@%@%@", serverAddress, @":", Port_Number, @"/", Router_Name];
}
- (void)setThemeColor:(UIColor *)themeColor {
    _themeColor = themeColor;
    [[UINavigationBar appearance] setBarTintColor:themeColor];
}
- (NSArray<NSString *> *)achieveTextArray {
    if (_achieveTextArray == nil) {
        _achieveTextArray = @[
                              @"跟进",
                              @"意向",
                              @"未成功沟通",
                              @"战败",
                              @"已加微信",
                              @"已付诚意金",
                              @"已下订",
                              @"待定到场",
                              @"确定到场",
                              @"约定到场",
                              @"实际到场"
                              ];
    }
    return _achieveTextArray;
}
- (NSArray<NSString *> *)achieveCodeArray {
    if (_achieveCodeArray == nil) {
        _achieveCodeArray = @[
                              @"BUS_FOLLOWUP",
                              @"BUS_INTENT",
                              @"BUS_NOLINK",
                              @"BUS_FAIL",
                              @"BUS_WECHART",
                              @"BUS_PAY",
                              @"BUS_ORDER",
                              @"BUS_READYCOME",
                              @"BUS_COME",
                              @"BUS_NOTPAY_PLANCOME",
                              @"BUS_REALCOME"
                              ];
    }
    return _achieveCodeArray;
}
- (NSArray<NSString *> *)matterTextArray {
    if (_matterTextArray == nil) {
        _matterTextArray = @[
                             @"首次跟进",
                             @"再次跟进",
                             @"计划到场"
                             ];
    }
    return _matterTextArray;
}
- (NSArray<NSString *> *)reportHeaderArray {
    if (_reportHeaderArray == nil) {
        _reportHeaderArray = @[
                               @"状态",
                               @"邀约",
                               @"诚意金",
                               @"订单"
                               ];
    }
    return _reportHeaderArray;
}
- (NSArray<NSString *> *)reportStateArray {
    if (_reportStateArray == nil) {
        _reportStateArray = @[
                              @"目前",
                              @"目标",
                              @"达成率"
                              ];
    }
    return _reportStateArray;
}
- (NSArray<NSString *> *)sequenceTextArray {
    if (_sequenceTextArray == nil) {
        _sequenceTextArray = @[
                           @"接收任务的时间",
                           @"计划到店时间",
                           @"联系次数",
                           @"计划下次回访时间",
                           @"实际到店时间"
                           ];
    }
    return _sequenceTextArray;
}
- (NSArray<NSString *> *)sequenceCodeArray {
    if (_sequenceCodeArray == nil) {
        _sequenceCodeArray = @[
                               @"RECEIVE_TIME",
                               @"PLAN_COME_TIME",
                               @"LINK_COUNT",
                               @"PLAN_FOLLOWUP_TIME",
                               @"REAL_COME_TIME",
                               ];
    }
    return _sequenceCodeArray;
}
- (NSArray<NSString *> *)againFollowUpLabelArray {
    if (_againFollowUpLabelArray == nil) {
        _againFollowUpLabelArray = @[
                                     @"已加微信",
                                     @"意向客户",
                                     @"未成功沟通",
                                     @"已交诚意金",
                                     @"未交诚意金",
                                     @"已下订金",
                                     @"未下订",
                                     @"已报名到场",
                                     @"待定到场",
                                     @"实际到场",
                                     ];
    }
    return _againFollowUpLabelArray;
}
- (NSArray<NSString *> *)againFollowUpCodeArray {
    if (_againFollowUpCodeArray == nil) {
        _againFollowUpCodeArray = @[
                                    @"IS_ADDWECHAT",
                                    @"IS_INTENT",
                                    @"IS_NOLINK",
                                    @"IS_PAY",
                                    @"IS_NOTPAY",
                                    @"IS_ORDER",
                                    @"IS_NOTORDER",
                                    @"IS_PLANCOME",
                                    @"IS_READYCOME",
                                    @"IS_COME",
                                    ];
    }
    return _againFollowUpCodeArray;
}
- (NSArray<NSString *> *)regardWords {
    if (_regardWords == nil) {
        _regardWords = @[
                         [@"早上好" S],
                         [@"上午好" S],
                         [@"中午好" S],
                         [@"下午好" S],
                         [@"晚上好" S]
                         ];
    }
    return _regardWords;
}
- (NSString *)regard {
    NSInteger time = [[[NSDate date] formatterDate:@"HH"] integerValue];
    NSInteger index = 4;
    if (time > 18) {
        index = 4;
    } else if (time > 14) {
        index = 3;
    } else if (time >= 12) {
        index = 2;
    } else if (time >= 9) {
        index = 1;
    } else if (time >= 6) {
        index = 0;
    }
    return self.regardWords[index];
}
@end
